package sesion08;

import java.util.Arrays;

public class EstadisticaArrays {

	public double max(double[] a) {
		double maximo = a[0];
		for (int i = 1; i < a.length; i++) {
			if (a[i] > maximo)
				maximo = a[i];
		}
		return maximo;
	}

	public double max(double[] a, int inferior, int superior) {
		return max(Arrays.copyOfRange(a, inferior, superior));
	}

	public int max(int[] a) {
		int maximo = a[0];
		for (int i = 1; i < a.length; i++) {
			if (a[i] > maximo)
				maximo = a[i];
		}
		return maximo;
	}

	public int max(int[] a, int inferior, int superior) {
		return max(Arrays.copyOfRange(a, inferior, superior));
	}
	
	public double min(double[] a) {
		double minimo = a[0];
		for (int i = 1; i < a.length; i++) {
			if (a[i] < minimo)
				minimo = a[i];
		}
		return minimo;
	}

	public double min(double[] a, int inferior, int superior) {
		return min(Arrays.copyOfRange(a, inferior, superior));
	}

	public int min(int[] a) {
		int minimo = a[0];
		for (int i = 1; i < a.length; i++) {
			if (a[i] < minimo)
				minimo = a[i];
		}
		return minimo;
	}

	public int min(int[] a, int inferior, int superior) {
		return min(Arrays.copyOfRange(a, inferior, superior));
	}
	
	public double media(double[] a) {
		return suma(a)/a.length;
	}
	
	public double suma(double[] a) {
		double suma = 0;
		for (int i = 1; i < a.length; i++) {
			suma+= a[i];
		}
		return suma;
	}

	public double media(double[] a, int inferior, int superior) {
		return media(Arrays.copyOfRange(a, inferior, superior));
	}

	public double media(int[] a) {
		int suma = 0;
		for (int i = 1; i < a.length; i++) {
			suma+= a[i];
		}
		return suma/a.length;
	}

	public double media(int[] a, int inferior, int superior) {
		return media(Arrays.copyOfRange(a, inferior, superior));
	}
	
	public double var(double[] a) {
		double media = media(a);
		double suma = 0;
		for (int i = 1; i < a.length; i++) {
			suma+= Math.pow((a[i]-media),2);
		}
		return suma/a.length-1;
	}

	public double var(double[] a, int inferior, int superior) {
		return var(Arrays.copyOfRange(a, inferior, superior));
	}

	public double var(int[] a) {
		double media = media(a);
		double suma = 0;
		for (int i = 1; i < a.length; i++) {
			suma+= Math.pow((a[i]-media),2);
		}
		return suma/a.length-1;
	}

	public double var(int[] a, int inferior, int superior) {
		return var(Arrays.copyOfRange(a, inferior, superior));
	}
	
	public double stdDev(double[] a) {
		return Math.sqrt(var(a));
	}

	public double stdDev(double[] a, int inferior, int superior) {
		return stdDev(Arrays.copyOfRange(a, inferior, superior));
	}

	public double stdDev(int[] a) {
	
		return Math.sqrt(var(a));
	}

	public double stdDev(int[] a, int inferior, int superior) {
		return stdDev(Arrays.copyOfRange(a, inferior, superior));
	}
	
	

}
